home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / winsr173.zip / WINDOS.C < prev    next >
C/C++ Source or Header  |  1992-07-20  |  42KB  |  1,518 lines

  1. /*
  2.     Routines which simulate DOS functions in the existing
  3.     Fractint for DOS
  4. */
  5.  
  6. #include "windows.h"
  7. #include "drivinit.h"
  8. #include "fractint.h"
  9. #include "winfract.h"
  10. #include <string.h>
  11. #include <time.h>
  12. #include <stdio.h>
  13.  
  14. #ifndef WINVER
  15. #define WINVER 0x0300        /* assume Windows 3.0 SDK if not found */
  16. #endif
  17.  
  18. #ifndef TIMERINFO
  19.                 /* define TIMERINFO stuff, if needs be */
  20. typedef struct tagTIMERINFO {
  21.     DWORD dwSize;
  22.     DWORD dwmsSinceStart;
  23.     DWORD dwmsThisVM;
  24.     } TIMERINFO;
  25.  
  26. BOOL    far pascal TimerCount(TIMERINFO FAR *);
  27. #endif
  28.  
  29. extern unsigned int windows_version;    /* 0x0300 = Win 3.0, 0x030A = 3.1 */
  30.  
  31.  
  32. int  farread(int, LPSTR, WORD);
  33. int  farwrite(int, LPSTR, WORD);
  34.  
  35. extern unsigned char FullPathName[];
  36. extern int FileFormat;
  37.  
  38. int save_system;       /* tag identifying Fractint for Windows */
  39. int save_release;       /* tag identifying version number */
  40. extern int win_release;    /* tag identifying version number  (in WINDOS2.C) */
  41.  
  42. extern BOOL bTrack, bMove;         /* TRUE if user is selecting a region */
  43. extern BOOL zoomflag;             /* TRUE is a zoom-box selected */
  44.  
  45. extern HWND hwnd;             /* handle to main window */
  46. extern HANDLE hInst;
  47.  
  48. extern HANDLE hAccTable;             /* handle to accelerator table */
  49.  
  50. extern char szHelpFileName[];         /* Help file name*/
  51.  
  52. extern int xdots, ydots, colors, maxiter;
  53. extern int xposition, yposition, win_xoffset, win_yoffset, xpagesize, ypagesize;
  54. extern int win_xdots, win_ydots;
  55.  
  56. extern int last_written_y;         /* last line written */
  57. extern int screen_to_be_cleared;     /* clear screen flag */
  58.  
  59. extern int time_to_act;          /* time to take some action? */
  60. extern int time_to_restart;         /* time to restart?  */
  61. extern int time_to_resume;         /* time to resume? */
  62. extern int time_to_quit;         /* time to quit? */
  63. extern int time_to_reinit;         /* time to reinitialize? */
  64. extern int time_to_load;         /* time to load? (DECODE) */
  65. extern int time_to_save;         /* time to save? (ENCODE) */
  66. extern int time_to_print;         /* time to print? (PRINTER) */
  67. extern int time_to_cycle;         /* time to begin color-cycling? */
  68. extern int time_to_starfield;        /* time to make a starfield? */
  69. extern int time_to_orbit;            /* time to activate orbits? */
  70.  
  71. extern unsigned char dacbox[256][3];
  72.  
  73. extern BOOL win_systempaletteused;    /* flag system palette set */
  74.  
  75. extern unsigned char far temp_array[];     /* temporary spot for Encoder rtns */
  76.  
  77. extern HANDLE hpixels;            /* handle to the DIB pixels */
  78. extern unsigned char huge *pixels;   /* the device-independent bitmap pixels */
  79. int pixels_per_byte;             /* pixels/byte in the pixmap */
  80. long pixels_per_bytem1;          /* pixels / byte - 1 (for ANDing) */
  81. int pixelshift_per_byte;         /* 0, 1, 2, or 3 */
  82. int bytes_per_pixelline;         /* pixels/line / pixels/byte */
  83. long win_bitmapsize;             /* bitmap size, in bytes */
  84.  
  85. extern int win_overlay3d;
  86. extern int win_display3d;
  87.  
  88. extern void center_window(HWND,int,int);
  89.  
  90. /****************************************************************************
  91.  
  92.     FUNCTION: keypressed(), getakey()
  93.  
  94.     PURPOSE:
  95.      keypressed()
  96.           Checks for, and processes, messages.
  97.           Returns -1 if it's time to wrap up and go home.
  98.           Returns 0 otherwise.
  99.     getakey()
  100.           same, but doesn't return until it's time to.
  101.  
  102.  
  103. ****************************************************************************/
  104.  
  105. BOOL dont_wait_for_a_key = TRUE;
  106.  
  107. #ifdef __BORLANDC__
  108.  
  109. /* Too many functions defaulting to a type 'int' return that should be
  110.    a type 'void'.  I'll just get rid of the warning message for this file
  111.    only.  MCP 8-6-91 */
  112.  
  113.    #pragma warn -rvl
  114.  
  115.    int LPTNumber;
  116.    int stackavail() { return(10240 + (signed int)_SP); }
  117. #else
  118.    int printf() {}
  119.    int _bios_serialcom(){}
  120. #endif
  121.  
  122.  
  123. extern int far wintext_textmode, far wintext_AltF4hit;
  124.  
  125. int getakey()
  126. {
  127. int i;
  128.  
  129. if (time_to_orbit) {  /* activate orbits? */
  130.     zoomflag = FALSE;
  131.     time_to_orbit = 0;
  132.     i = 'o';
  133.     return(i);
  134.     }
  135.  
  136. dont_wait_for_a_key = FALSE;
  137. i = keypressed();
  138. dont_wait_for_a_key = TRUE;
  139. zoomflag = FALSE;
  140. return(i);
  141.  
  142. }
  143.  
  144. int keypressed()
  145. {
  146. MSG msg;
  147. int time_to;
  148.  
  149. /* is a text-mode screen active? */
  150. if (wintext_textmode == 2 || wintext_AltF4hit) {
  151.     if (dont_wait_for_a_key)
  152.         return(fractint_getkeypress(0));
  153.     else
  154.         return(fractint_getkeypress(1));
  155.     }
  156.  
  157. if (dont_wait_for_a_key)
  158.     if (PeekMessage(&msg, NULL, NULL, NULL, PM_NOREMOVE) == 0) {
  159.     time_to = time_to_act + time_to_reinit+time_to_restart+time_to_quit+
  160.         time_to_load+time_to_save+time_to_print+time_to_cycle+
  161.         time_to_resume+time_to_starfield;
  162.     if (time_to_orbit) {  /* activate orbits? */
  163.         time_to = 'o';
  164.         }
  165.     /* bail out if nothing is happening */
  166.     return(time_to);
  167.     }
  168.  
  169. while (GetMessage(&msg, NULL, NULL, NULL)) {
  170.  
  171.     if (!TranslateAccelerator(hwnd, hAccTable, &msg)) {
  172.         TranslateMessage(&msg);
  173.         DispatchMessage(&msg);
  174.         }
  175.  
  176.     CheckMathTools();
  177.     if (!bTrack && !bMove) {          /* don't do this if mouse-button is down */
  178.     time_to = time_to_act+time_to_reinit+time_to_restart+time_to_quit+
  179.         time_to_load+time_to_save+time_to_print+time_to_cycle+
  180.         time_to_starfield;
  181.     if (time_to_orbit) {  /* activate orbits? */
  182.         time_to = 'o';
  183.         }
  184.     if (dont_wait_for_a_key || time_to)
  185.         return(time_to);
  186.     }
  187.  
  188.     }
  189.  
  190. if (!dont_wait_for_a_key)
  191.     time_to_quit = 1;
  192.  
  193.     /* bail out if nothing is happening */
  194.     time_to = time_to_act+time_to_reinit+time_to_restart+time_to_quit+
  195.     time_to_load+time_to_save+time_to_print+time_to_cycle;
  196.     if (time_to_orbit) {  /* activate orbits? */
  197.         time_to = 'o';
  198.         }
  199.     return(time_to);
  200.  
  201. }
  202.  
  203. int  farread(int handle, LPSTR buf, WORD len)
  204. {
  205. int i;
  206.  
  207.     i = _lread(handle, buf, len);
  208.     return(i);
  209.  
  210. }
  211.  
  212. int  farwrite(int handle, LPSTR buf, WORD len)
  213. {
  214.  
  215.     return(_lwrite(handle, buf, len));
  216.  
  217. }
  218.  
  219.  
  220. /****************************************************************************
  221.  
  222.     FUNCTION: putcolor(int x, int y, int color), getcolor(int x, int y)
  223.  
  224.     PURPOSE:
  225.     putcolor:
  226.        sets the "color" value of the pixel at location x,y
  227.        (actually, a palette value)
  228.     getcolor:
  229.        returns the "color" value of the pixel at location x,y
  230.        (actually, a palette value)
  231.  
  232. ****************************************************************************/
  233.  
  234. extern int win_fastupdate;
  235.  
  236. time_t last_time;
  237. time_t update_time;
  238. long minimum_update;
  239. long pixelsout;
  240. int top_changed, bottom_changed;
  241.  
  242. /* Made global, MCP 6-16-91 */
  243. unsigned char win_andmask[8];
  244. unsigned char win_notmask[8];
  245. unsigned char win_bitshift[8];
  246.  
  247. void putcolor(int x, int y, int color)
  248. {
  249. RECT tempRect;             /* temporary rectangle structure */
  250. long i;
  251. int temp_top_changed, temp_bottom_changed;
  252. time_t this_time;
  253.  
  254. last_written_y = y;
  255. if (y < top_changed) top_changed = y;
  256. if (y > bottom_changed) bottom_changed = y;
  257.  
  258. i = win_ydots-1-y;
  259. i = (i * win_xdots) + x;
  260.  
  261. if (x >= 0 && x < xdots && y >= 0 && y < ydots) {
  262.     if (pixelshift_per_byte == 0) {
  263.       pixels[i] = color % colors;
  264.       }
  265.      else {
  266.       unsigned int j;
  267.       j = i & pixels_per_bytem1;
  268.       i = i >> pixelshift_per_byte;
  269.       pixels[i] = (pixels[i] & win_notmask[j]) +
  270.           (((unsigned char)(color % colors)) << win_bitshift[j]);
  271.       }
  272.  
  273.      /* check the time every nnn pixels */
  274.      if (win_fastupdate || ++pixelsout > 100) {
  275.       pixelsout = 0;
  276.       this_time = time(NULL);
  277.       /* time to update the screen? */
  278.       if (win_fastupdate || (this_time - last_time) > update_time ||
  279.           (minimum_update*(this_time-last_time)) > (bottom_changed-top_changed)) {
  280.           temp_top_changed = top_changed - win_yoffset;
  281.           temp_bottom_changed = bottom_changed - win_yoffset;
  282.           if (!(temp_top_changed >= ypagesize || temp_bottom_changed < 0)) {
  283.           if (temp_top_changed    < 0) temp_top_changed    = 0;
  284.           if (temp_bottom_changed < 0) temp_bottom_changed = 0;
  285.           if (temp_top_changed    > ypagesize) temp_top_changed    = ypagesize;
  286.           if (temp_bottom_changed > ypagesize) temp_bottom_changed = ypagesize;
  287.           tempRect.top = temp_top_changed;
  288.           tempRect.bottom = temp_bottom_changed+1;
  289.           tempRect.left = 0;
  290.           tempRect.right = xdots;
  291.                   if (win_fastupdate == 1) {
  292.                       tempRect.left =  x-win_xoffset;
  293.                       tempRect.right = x-win_xoffset+1;
  294.                       }
  295.           InvalidateRect(hwnd, &tempRect, FALSE);
  296. /*
  297.                   EndDeferWindowPos(BeginDeferWindowPos(0));
  298. */
  299.           }
  300.           if (win_fastupdate) {
  301.                   extern int kbdcount;
  302.                   if (kbdcount > 5)
  303.                       kbdcount = 5;
  304.               win_fastupdate = 1;
  305.               }
  306.           keypressed();    /* force a look-see at the screen */
  307.           last_time = this_time;
  308.           top_changed = win_ydots;
  309.           bottom_changed = 0;
  310.           }
  311.       }
  312.      }
  313.  
  314. }
  315.  
  316. int getcolor(int x, int y)
  317. {
  318. long i;
  319.  
  320. i = win_ydots-1-y;
  321. i = (i * win_xdots) + x;
  322.  
  323. if (x >= 0 && x < xdots && y >= 0 && y < ydots) {
  324.     if (pixelshift_per_byte == 0) {
  325.       return(pixels[i]);
  326.       }
  327.      else {
  328.       unsigned int j;
  329.       j = i & pixels_per_bytem1;
  330.       i = i >> pixelshift_per_byte;
  331.       return((int)((pixels[i] & win_andmask[j]) >> win_bitshift[j]));
  332.       }
  333.      }
  334. else
  335.      return(0);
  336. }
  337.  
  338. int put_line(int rownum, int leftpt, int rightpt, unsigned char *localvalues)
  339. {
  340. int i, len;
  341. long startloc;
  342.  
  343. len = rightpt - leftpt;
  344. if (rightpt >= xdots) len = xdots - 1 - leftpt;
  345. startloc = win_ydots-1-rownum;
  346. startloc = (startloc * win_xdots) + leftpt;
  347.  
  348. if (rownum < 0 || rownum >= ydots || leftpt < 0) {
  349.     return(0);
  350.     }
  351.  
  352. if (pixelshift_per_byte == 0) {
  353.     for (i = 0; i <= len; i++)
  354.     pixels[startloc+i] = localvalues[i];
  355.     }
  356. else {
  357.     unsigned int j;
  358.     long k;
  359.     for (i = 0; i <= len; i++) {
  360.     k = startloc + i;
  361.     j = k & pixels_per_bytem1;
  362.     k = k >> pixelshift_per_byte;
  363.     pixels[k] = (pixels[k] & win_notmask[j]) +
  364.         (((unsigned char)(localvalues[i] % colors)) << win_bitshift[j]);
  365.     }
  366.     }
  367. pixelsout += len;
  368. if (win_fastupdate)
  369.     win_fastupdate = 2;  /* force 'putcolor()' to update a whole scanline */
  370. putcolor(leftpt, rownum, localvalues[0]);
  371. }
  372.  
  373. int get_line(int rownum, int leftpt, int rightpt, unsigned char *localvalues)
  374. {
  375. int i, len;
  376. long startloc;
  377.  
  378. len = rightpt - leftpt;
  379. if (rightpt >= xdots) len = xdots - 1 - leftpt;
  380. startloc = win_ydots-1-rownum;
  381. startloc = (startloc * win_xdots) + leftpt;
  382.  
  383. if (rownum < 0 || rownum >= ydots || leftpt < 0 || rightpt >= xdots) {
  384.     for (i = 0; i <= len; i++)
  385.     localvalues[i] = 0;
  386.     return(0);
  387.     }
  388.  
  389. if (pixelshift_per_byte == 0) {
  390.     for (i = 0; i <= len; i++)
  391.     localvalues[i] = pixels[startloc+i];
  392.     }
  393. else {
  394.     unsigned int j;
  395.     long k;
  396.     for (i = 0; i <= len; i++) {
  397.     k = startloc + i;
  398.     j = k & pixels_per_bytem1;
  399.     k = k >> pixelshift_per_byte;
  400.     localvalues[i] = (pixels[k] & win_andmask[j]) >> win_bitshift[j];
  401.     }
  402.     }
  403. }
  404.  
  405. extern int rowcount;
  406.  
  407. int out_line(unsigned char *localvalues, int numberofdots)
  408. {
  409.     put_line(rowcount++, 0, numberofdots, localvalues);
  410. }
  411.  
  412. extern LPBITMAPINFO pDibInfo;        /* pointer to the DIB info */
  413.  
  414. int clear_screen(int forceclear)
  415. {
  416. long numdots;
  417. int i;
  418.  
  419. /* set up the videoentry values */
  420. strcpy(videoentry.name,   "Windows Video Image");
  421. strcpy(videoentry.comment,"Generated using Winfract");
  422. videoentry.keynum      = 40;
  423. videoentry.videomodeax = 3;
  424. videoentry.videomodebx = 0;
  425. videoentry.videomodecx = 0;
  426. videoentry.videomodedx = 0;
  427. videoentry.dotmode     = 1;
  428. videoentry.xdots       = xdots;
  429. videoentry.ydots       = ydots;
  430. videoentry.colors      = colors;
  431.  
  432. win_xdots = (xdots+3) & 0xfffc;
  433. win_ydots = ydots;
  434. pixelshift_per_byte = 0;
  435. pixels_per_byte   = 1;
  436. pixels_per_bytem1 = 0;
  437. if (colors == 16) {
  438.     win_xdots = (xdots+7) & 0xfff8;
  439.     pixelshift_per_byte = 1;
  440.     pixels_per_byte = 2;
  441.     pixels_per_bytem1 = 1;
  442.     win_andmask[0] = 0xf0;  win_notmask[0] = 0x0f; win_bitshift[0] = 4;
  443.     win_andmask[1] = 0x0f;  win_notmask[1] = 0xf0; win_bitshift[1] = 0;
  444.     }
  445. if (colors == 2) {
  446.     win_xdots = (xdots+31) & 0xffe0;
  447.     pixelshift_per_byte = 3;
  448.     pixels_per_byte = 8;
  449.     pixels_per_bytem1 = 7;
  450.     win_andmask[0] = 0x80;  win_notmask[0] = 0x7f; win_bitshift[0] = 7;
  451.     for (i = 1; i < 8; i++) {
  452.     win_andmask[i] = win_andmask[i-1] >> 1;
  453.     win_notmask[i] = (win_notmask[i-1] >> 1) + 0x80;
  454.     win_bitshift[i] = win_bitshift[i-1] - 1;
  455.     }
  456.     }
  457.  
  458. numdots = (long)win_xdots * (long) win_ydots;
  459. update_time = 2;
  460. /* disable the long delay logic 
  461. if (numdots > 200000L) update_time = 4;
  462. if (numdots > 400000L) update_time = 8;
  463. */
  464. last_time = time(NULL) - update_time + 1;
  465. minimum_update = 7500/xdots;    /* assume 75,000 dots/sec drawing speed */
  466.  
  467. last_written_y = -1;
  468. pixelsout = 0;
  469. top_changed = win_ydots;
  470. bottom_changed = 0;
  471.  
  472. bytes_per_pixelline = win_xdots >> pixelshift_per_byte;
  473.  
  474. /* Create the Device-independent Bitmap entries */
  475. pDibInfo->bmiHeader.biWidth  = win_xdots;
  476. pDibInfo->bmiHeader.biHeight = win_ydots;
  477. pDibInfo->bmiHeader.biSizeImage = (DWORD)bytes_per_pixelline * win_ydots;
  478. pDibInfo->bmiHeader.biBitCount = 8 / pixels_per_byte;
  479.  
  480. /* hard to believe, but this is the fast way to clear the pixel map */
  481. if (hpixels) {
  482.      GlobalUnlock(hpixels);
  483.      GlobalFree(hpixels);
  484.      }
  485.  
  486. win_bitmapsize = (numdots >> pixelshift_per_byte)+1;
  487.  
  488. if (!(hpixels = GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, win_bitmapsize)))
  489.      return(0);
  490. if (!(pixels = (char huge *)GlobalLock(hpixels))) {
  491.      GlobalFree(hpixels);
  492.      return(0);
  493.      }
  494.  
  495. /* adjust the colors for B&W or default */
  496. if (colors == 2) {
  497.     dacbox[0][0] = dacbox[0][1] = dacbox[0][2] = 0;
  498.     dacbox[1][0] = dacbox[1][1] = dacbox[1][2] = 63;
  499.     spindac(0,1);
  500.     }
  501. else
  502.     restoredac();   /* color palette */
  503.  
  504. screen_to_be_cleared = 1;
  505. InvalidateRect(hwnd, NULL, TRUE);
  506.  
  507. if (forceclear)
  508.     keypressed();        /* force a look-see at the screen */
  509.  
  510. return(1);
  511. }
  512.  
  513. int flush_screen()
  514. {
  515.  
  516. last_written_y = 0;
  517.  
  518. InvalidateRect(hwnd, NULL, FALSE);
  519.  
  520. }
  521.  
  522. /****************************************************************************
  523.  
  524.     FUNCTION: buzzer(int buzzertype)
  525.  
  526.     PURPOSE:
  527.           make some sort of sound (hey, we do what we can)
  528.  
  529. ****************************************************************************/
  530.  
  531. void buzzer(int i)
  532. {
  533.  
  534. MessageBeep(0);
  535.  
  536. }
  537.  
  538. /****************************************************************************
  539.  
  540.     FUNCTION: unsigned char far * farmemalloc(long bytecount)
  541.           void farmemfree(unsigned char * bytepointer)
  542.     PURPOSE:
  543.           allocate and free memory in a manner consistent with
  544.           Fractint for DOS
  545.  
  546. ****************************************************************************/
  547.  
  548. #define MAXFARMEMALLOCS  50        /* max active farmemallocs */
  549. int   farmemallocinit = 0;        /* any memory been allocated yet?   */
  550. HANDLE farmemallochandles[MAXFARMEMALLOCS];            /* handles  */
  551. void far *farmemallocpointers[MAXFARMEMALLOCS]; /* pointers */
  552.  
  553. void far * farmemalloc(long bytecount)
  554. {
  555. int i;
  556. HANDLE temphandle;
  557. unsigned char far *temppointer;
  558.  
  559. if (!farmemallocinit) {     /* never been here yet - initialize */
  560.     farmemallocinit = 1;
  561.     for (i = 0; i < MAXFARMEMALLOCS; i++) {
  562.     farmemallochandles[i] = (HANDLE)0;
  563.     farmemallocpointers[i] = NULL;
  564.     }
  565.     }
  566.  
  567. for (i = 0; i < MAXFARMEMALLOCS; i++)  /* look for a free handle */
  568.     if (farmemallochandles[i] == (HANDLE)0) break;
  569.  
  570. if (i == MAXFARMEMALLOCS)    /* uh-oh - no more handles */
  571.    return(NULL);        /* can't get far memory this way */
  572.  
  573. if (!(temphandle = GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, bytecount)))
  574.      return(NULL);        /* can't allocate the memory */
  575. if (!(temppointer = (unsigned char far *)GlobalLock(temphandle))) {
  576.      GlobalFree(temphandle);
  577.      return(NULL);        /* ?? can't lock the memory ?? */
  578.      }
  579.  
  580. farmemallochandles[i] =  temphandle;
  581. farmemallocpointers[i] = temppointer;
  582. return(temppointer);
  583. }
  584.  
  585. void farmemfree(void far *bytepointer)
  586. {
  587. int i;
  588.  
  589. if (bytepointer == (void far *)NULL) return;
  590.  
  591. for (i = 0; i < MAXFARMEMALLOCS; i++)    /* search for a matching pointer */
  592.     if (farmemallocpointers[i] == bytepointer)
  593.      break;
  594. if (i < MAXFARMEMALLOCS) {        /* got one */
  595.     GlobalUnlock(farmemallochandles[i]);
  596.     GlobalFree(farmemallochandles[i]);
  597.     farmemallochandles[i] = (HANDLE)0;
  598.     }
  599.  
  600. }
  601.  
  602. debugmessage(char *msg1, char *msg2)
  603. {
  604. MessageBox (
  605.     GetFocus(),
  606.     msg2,
  607.     msg1,
  608.     MB_ICONASTERISK | MB_OK);
  609.  
  610. }
  611.  
  612. texttempmsg(char *msg1)
  613. {
  614. MessageBox (
  615.     GetFocus(),
  616.     msg1,
  617.     "Encoder",
  618.     MB_ICONASTERISK | MB_OK);
  619. }
  620.  
  621. stopmsg(int flags, unsigned char far *msg1)
  622. {
  623. int result;
  624.  
  625. if (! (flags & 4)) MessageBeep(0);
  626.  
  627. result = IDOK;
  628.  
  629. if (!(flags & 2))
  630.     MessageBox (
  631.     NULL,
  632.     msg1,
  633.     "Fractint for Windows",
  634.     MB_TASKMODAL | MB_ICONASTERISK | MB_OK);
  635. else
  636.     result = MessageBox (
  637.     NULL,
  638.     msg1,
  639.     "Fractint for Windows",
  640.     MB_TASKMODAL | MB_ICONQUESTION | MB_OKCANCEL);
  641.  
  642. if (result == 0 || result == IDOK || result == IDYES)
  643.     return(0);
  644. else
  645.     return(-1);
  646. }
  647.  
  648. extern char readname[];
  649. extern int fileydots, filexdots, filecolors;
  650. extern int     iNumColors;    /* Number of colors supported by device           */
  651. extern int     iRasterCaps;   /* Raster capabilities                   */
  652.  
  653. win_load()
  654. {
  655. int i;
  656.  
  657. time_to_load = 0;
  658.  
  659.     start_wait();
  660.     if ((i = read_overlay()) >= 0 && (!win_display3d ||
  661.     xdots < filexdots || ydots < fileydots)) {
  662.     if (win_display3d) stopmsg(0,
  663.         "3D and Overlay3D file image sizes must be\nat least as large as the display image.\nAltering your display image to match the file.");
  664.     xdots = filexdots;
  665.     ydots = fileydots;
  666.     colors = filecolors;
  667.     if (colors > 16) colors = 256;
  668.     if (colors >  2 && colors < 16) colors = 16;
  669.     if (xdots < 50) xdots = 50;
  670.     if (xdots > 2048) xdots = 2048;
  671.     if (ydots < 50) ydots = 50;
  672.     if (ydots > 2048) ydots = 2048;
  673.     set_win_offset();
  674.     clear_screen(0);
  675.     }
  676.     end_wait();
  677.     return(i);
  678. }
  679.  
  680. win_save()
  681. {
  682.     time_to_save = 0;
  683.     save_system = 1;
  684.     save_release = win_release;
  685.  
  686.     /* MCP 10-27-91 */
  687.     if(FileFormat != ID_BMP)
  688.        savetodisk(readname);
  689.     else
  690.        SaveBitmapFile(hwnd, FullPathName);
  691.     CloseStatusBox();
  692. }
  693.  
  694.  
  695. /********************    Printer logic    *********************/
  696.  
  697. static struct PRINFO { /* dynamic alloc these to avoid eating static space */
  698.     HDC printerDC;        /* printer device context */
  699.     HANDLE hdm;         /* memory handle for next, NULL if none */
  700.     LPDEVMODE dm;        /* devmode block from printer */
  701.     BOOL b_print_abort;     /* abort flag from abort routine */
  702.     HWND h_pabort_dialog;    /* handle for abort window */
  703.     char drivername[41];
  704.     char devname[61];
  705.     char outname[41];
  706.     int cur_orient;        /* current options, saved if dialog ok'd */
  707.     int cur_maxflag;
  708.     float cur_width;
  709.     int width_ok;        /* FALSE if width currently in error */
  710.     float printer_xsize;    /* size of max print area in inches */
  711.     float printer_ysize;
  712.     int printer_xpix;        /* number of pixels across max print area */
  713.     int printer_ypix;
  714.     } far *pr;
  715.  
  716. static int pr_orient  = DMORIENT_LANDSCAPE; /* user selected orientation */
  717. static int pr_maxflag = 1;            /* user selected max size?     */
  718. static float pr_width = 0;            /* user selected width     */
  719.  
  720. static void create_printer_DC()
  721. {
  722.     HDC displayDC;
  723.     float daspect, paspect;
  724.     int printer_xdots, printer_ydots;
  725.     if (pr->printerDC) /* ditch the old one first if present */
  726.     DeleteDC(pr->printerDC);
  727.     if (!pr->dm) /* no DEVMODE, an old driver? */
  728.     pr->printerDC = CreateDC(pr->drivername, pr->devname, pr->outname, NULL);
  729.     else { /* got DEVMODE block so get fancy */
  730.     if ((pr->dm->dmFields & DM_ORIENTATION))
  731.         pr->dm->dmOrientation = pr->cur_orient;
  732.     if ((pr->dm->dmFields & DM_COLOR))
  733.         pr->dm->dmColor = DMCOLOR_COLOR;
  734.     pr->printerDC = CreateDC(pr->drivername, pr->devname, pr->outname, (LPSTR)pr->dm);
  735.     }
  736.     if (pr->printerDC) { /* calculate size of max area on printer */
  737.     displayDC = GetDC(NULL);
  738.     daspect = ((float)xdots / GetDeviceCaps(displayDC,LOGPIXELSX))
  739.         / ((float)ydots / GetDeviceCaps(displayDC,LOGPIXELSY));
  740.     ReleaseDC(NULL,displayDC);
  741.     printer_xdots = GetDeviceCaps(pr->printerDC,HORZRES);
  742.     printer_ydots = GetDeviceCaps(pr->printerDC,VERTRES);
  743.     paspect = ((float)printer_xdots / GetDeviceCaps(pr->printerDC,HORZSIZE))
  744.         / ((float)printer_ydots / GetDeviceCaps(pr->printerDC,VERTSIZE));
  745.     pr->printer_xpix = printer_xdots;
  746.     pr->printer_ypix = (float)printer_xdots / daspect / paspect;
  747.     if (pr->printer_ypix > printer_ydots) {
  748.         pr->printer_xpix = (float)pr->printer_xpix * (float) printer_ydots
  749.                  / (float)pr->printer_ypix;
  750.         if (pr->printer_xpix > printer_xdots)
  751.         pr->printer_xpix = printer_xdots;
  752.         pr->printer_ypix = printer_ydots;
  753.         }
  754.     pr->printer_xsize = (float)pr->printer_xpix
  755.               / GetDeviceCaps(pr->printerDC,LOGPIXELSX);
  756.     pr->printer_ysize = (float)pr->printer_ypix
  757.               / GetDeviceCaps(pr->printerDC,LOGPIXELSY);
  758.     }
  759. }
  760.  
  761. static void show_printsizes(HWND hDlg)
  762. {
  763.     HWND tmphwnd;
  764.     char buf[80];
  765.     sprintf(buf,"(%.2f x %.2f inches)",pr->printer_xsize,pr->printer_ysize);
  766.     SetDlgItemText(hDlg,ID_PRS_MAXSIZ,buf);
  767.     if (pr->cur_width == 0 || pr->cur_width > pr->printer_xsize)
  768.     pr->cur_width = pr->printer_xsize;
  769.     sprintf(buf,"%.2f",pr->cur_width);
  770.     SetDlgItemText(hDlg,ID_PRS_WIDTH,buf);
  771.     tmphwnd = GetDlgItem(hDlg,ID_PRS_WIDTH);
  772.     EnableWindow(tmphwnd,1 ^ pr->cur_maxflag); /* grey if max selected */
  773. }
  774.  
  775. BOOL FAR PASCAL PrintDlg(HWND hDlg, unsigned msg, WORD wParam, LONG lParam)
  776. {
  777.     int i;
  778.     HWND tmphwnd;
  779.     char buf[120];
  780.     float f;
  781.  
  782.     switch (msg) {
  783.  
  784.       case WM_INITDIALOG:
  785.     center_window(hDlg,0,0);
  786.     _fstrcpy((char far *)buf,pr->devname);
  787.     strcat(buf," on ");
  788.     _fstrcat((char far *)buf,pr->outname);
  789.     if (buf[i=strlen(buf)-1] == ':') buf[i] = 0;
  790.     SetDlgItemText(hDlg,ID_PR_DEVICE,buf);
  791.     if (!pr->dm || !(pr->dm->dmFields & DM_ORIENTATION)) {
  792.         i = 1; /* must use portrait */
  793.         tmphwnd = GetDlgItem(hDlg,ID_PRO_LANDS);
  794.         EnableWindow(tmphwnd,0);
  795.         }
  796.     else
  797.         i = (pr->cur_orient == DMORIENT_LANDSCAPE) ? 0 : 1;
  798.     CheckDlgButton(hDlg, ID_PRO_PORTR, i);
  799.     CheckDlgButton(hDlg, ID_PRO_LANDS, i ^ 1);
  800.     CheckDlgButton(hDlg, ID_PRS_MAX,  pr->cur_maxflag);
  801.     CheckDlgButton(hDlg, ID_PRS_CUST, pr->cur_maxflag ^ 1);
  802.     show_printsizes(hDlg); /* show the rest */
  803.     break;
  804.  
  805.       case WM_COMMAND:
  806.     switch (wParam) {
  807.       case IDOK:
  808.         if (pr->cur_maxflag == 0 && !pr->width_ok) {
  809.         MessageBeep(0);
  810.         SetFocus(GetDlgItem(hDlg, ID_PRS_WIDTH));
  811.         break;
  812.         }
  813.         EndDialog(hDlg, 1);
  814.         break;
  815.       case IDCANCEL:
  816.         EndDialog(hDlg, 0);
  817.         break;
  818.       case ID_PRO_PORTR:
  819.       case ID_PRO_LANDS:
  820.         pr->cur_orient = (wParam == ID_PRO_PORTR)
  821.                ? DMORIENT_PORTRAIT : DMORIENT_LANDSCAPE;
  822.         if (pr->cur_width == pr->printer_xsize)
  823.         pr->cur_width = 0; /* force reset to match new size */
  824.         create_printer_DC();   /* new device context for new orient */
  825.         show_printsizes(hDlg); /* display new orientation sizes */
  826.         break;
  827.       case ID_PRS_MAX:
  828.       case ID_PRS_CUST:
  829.         pr->cur_maxflag = (wParam == ID_PRS_MAX) ? 1 : 0;
  830.         show_printsizes(hDlg); /* to set width field grey status */
  831.         break;
  832.       case ID_PRS_WIDTH:
  833.         switch(HIWORD(lParam)) {
  834.           case EN_KILLFOCUS:
  835.         GetDlgItemText(hDlg, ID_PRS_WIDTH, buf, 20);
  836.         i = strlen(buf);
  837.         while (i > 0 && buf[i] == ' ') --i;
  838.         buf[i] = 0;
  839.         if (sscanf(buf,"%f%c",&f) == 1 /* got a float */
  840.           && f <= pr->printer_xsize) { /* not greater than max */
  841.             pr->cur_width = f;
  842.             pr->width_ok = TRUE;
  843.             show_printsizes(hDlg); /* redisplay, formatted */
  844.             }
  845.         else /* entry invalid */
  846.             pr->width_ok = FALSE;
  847.         break;
  848.           default:
  849.         return FALSE;
  850.           }
  851.         break;
  852.       default:
  853.         return FALSE;
  854.       }
  855.     break;
  856.  
  857.       case WM_KEYDOWN:
  858.     switch (wParam) {
  859.       case VK_F1:
  860.         /* F1, shifted F1 bring up the Help Index */
  861.         WinHelp(hwnd,szHelpFileName,HELP_INDEX,0L);
  862.         break;
  863.       default:
  864.         return FALSE;
  865.       }
  866.     break;
  867.  
  868.       default:
  869.     return FALSE;
  870.  
  871.       }
  872.     return TRUE;
  873. }
  874.  
  875. int FAR PASCAL PrintAbortDlg(HWND hWnd, unsigned msg, WORD wParam, LONG lParam)
  876. {
  877.     if (msg == WM_COMMAND) { /* Cancel button (Enter, Esc, Return, Space) */
  878.     pr->b_print_abort = TRUE;
  879.     DestroyWindow(hWnd);
  880.     return (TRUE);
  881.     }
  882.     if (msg == WM_INITDIALOG) {
  883.     center_window(hWnd,0,0);
  884.     SetFocus(hWnd);
  885.     return (TRUE);
  886.     }
  887.     return (FALSE);
  888. }
  889.  
  890. int FAR PASCAL PrintAbort(HDC hPr, int Code)
  891. {
  892.     MSG msg;
  893.     while (PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE))
  894.     if (!IsDialogMessage(pr->h_pabort_dialog, &msg)) {
  895.         TranslateMessage(&msg);
  896.         DispatchMessage(&msg);
  897.         }
  898.     return (!pr->b_print_abort); /* return FALSE iff aborted */
  899. }
  900.  
  901. void win_print()
  902. {
  903.     HANDLE hpr;
  904.     int Return;
  905.     int printer_bandable;
  906.     long firstpixel;
  907.     RECT printerRect;
  908.     int more;
  909.     FARPROC lpPrintDlg;
  910.     FARPROC p_print_abort;
  911.     FARPROC p_pabort_dialog;
  912.     int printer_xacross, printer_yacross;
  913.  
  914.     time_to_print = 0;
  915.     hpr = GlobalAlloc(GMEM_FIXED, sizeof(struct PRINFO));
  916.     pr    = (struct PRINFO FAR *)GlobalLock(hpr);
  917.     pr->printerDC = NULL;
  918.     pr->hdm = NULL;
  919.     pr->cur_orient  = pr_orient;
  920.     pr->cur_maxflag = pr_maxflag;
  921.     pr->cur_width   = pr_width;
  922.     pr->width_ok = TRUE;
  923.  
  924.     { /* find the default printer */
  925.     char szPrinter[80];
  926.     char *szDevice, *szDriver, *szOutput;
  927.     int dmsize;
  928.     dmsize = 0;
  929.     GetProfileString ("windows", "device", "", szPrinter, sizeof(szPrinter));
  930.     if ( (szDevice = strtok (szPrinter, "," ))
  931.       && (szDriver = strtok (NULL,    ", "))
  932.       && (szOutput = strtok (NULL,    ", "))) {
  933.     char drivname[40];
  934.     HANDLE hDriver;
  935.     int (FAR PASCAL *p_ExtDeviceMode)(HWND,HANDLE,DEVMODE FAR *,LPSTR,LPSTR,DEVMODE FAR *,LPSTR,WORD);
  936.     _fstrncpy(pr->drivername,(char far *)szDriver,40);
  937.     _fstrncpy(pr->devname,     (char far *)szDevice,60);
  938.     _fstrncpy(pr->outname,     (char far *)szOutput,40);
  939.     pr->drivername[40] = 0;
  940.     pr->devname   [60] = 0;
  941.     pr->outname   [40] = 0;
  942.     strcpy(drivname,szDriver); strcat(drivname,".drv");
  943.     if ((hDriver = LoadLibrary(drivname)) >= 32) { /* else driver not found */
  944.         if ((p_ExtDeviceMode = GetProcAddress(hDriver,"ExtDeviceMode"))
  945.           && (dmsize = (*p_ExtDeviceMode)(NULL,hDriver,NULL,szDevice,szOutput,NULL,NULL,0)) > 0) {
  946.         /* load DEVMODE block */
  947.         pr->hdm = GlobalAlloc(GMEM_FIXED, dmsize);
  948.         pr->dm    = (DEVMODE FAR *)GlobalLock(pr->hdm);
  949.         (*p_ExtDeviceMode)(NULL,hDriver,pr->dm,szDevice,szOutput,NULL,NULL,DM_COPY);
  950.         }
  951.         FreeLibrary(hDriver);
  952.         }
  953.     create_printer_DC();
  954.     }
  955.     if (!pr->printerDC) {
  956.     stopmsg(0,"Can't find the printer!");
  957.     goto win_print_exit;
  958.     }
  959.     }
  960.  
  961.     /* get user options */
  962.     lpPrintDlg = MakeProcInstance((FARPROC) PrintDlg, hInst);
  963.     Return = DialogBox(hInst, "Printoptions", hwnd, lpPrintDlg);
  964.     FreeProcInstance(lpPrintDlg);
  965.     if (Return == 0) /* cancelled */
  966.     goto win_print_exit;
  967.     pr_orient  = pr->cur_orient;    /* not cancelled, remember options */
  968.     pr_maxflag = pr->cur_maxflag;
  969.     pr_width   = pr->cur_width;
  970.  
  971.     start_wait();
  972.  
  973.     printer_bandable =    GetDeviceCaps(pr->printerDC,RASTERCAPS) & RC_BANDING;
  974. /*
  975.     printer_bandable = 0;
  976. */
  977.  
  978.     /* calc print position & size, set up colors */
  979.     firstpixel = win_ydots - ydots;
  980.     firstpixel = firstpixel * bytes_per_pixelline;
  981.     printer_xacross = pr->printer_xpix;
  982.     printer_yacross = pr->printer_ypix;
  983.     if (pr->cur_maxflag == 0 && pr->cur_width != pr->printer_xsize) {
  984.     float f;
  985.     f = pr->cur_width / pr->printer_xsize;
  986.     printer_xacross = f * printer_xacross;
  987.     printer_yacross = f * printer_yacross;
  988.     }
  989.     if (GetDeviceCaps(pr->printerDC,NUMCOLORS) <= 2)
  990.     mono_dib_palette();    /* B&W stripes for B&W printers */
  991.     else
  992.     rgb_dib_palette();
  993.  
  994.     /* set up abort logic */
  995.     pr->b_print_abort = FALSE;
  996.     p_print_abort  = MakeProcInstance(PrintAbort,    hInst);
  997.     p_pabort_dialog = MakeProcInstance(PrintAbortDlg, hInst);
  998.     pr->h_pabort_dialog = CreateDialog(hInst, "Printabort", hwnd, p_pabort_dialog);
  999.     ShowWindow(pr->h_pabort_dialog, SW_NORMAL);
  1000.     UpdateWindow(pr->h_pabort_dialog);
  1001.     EnableWindow(hwnd, FALSE);
  1002.     Return = Escape (pr->printerDC, SETABORTPROC, 0, (LPSTR)p_print_abort, NULL);
  1003.     if (Return <= 0 || pr->b_print_abort) goto oops;
  1004.  
  1005.     /* print */
  1006.     Return = Escape (pr->printerDC, STARTDOC, 17, (LPSTR)"Fractint Printout", NULL);
  1007.     if (Return <= 0 || pr->b_print_abort) goto oops;
  1008.     if (printer_bandable) {
  1009.     Return = Escape(pr->printerDC, NEXTBAND, 0, (LPSTR) NULL, (LPSTR) &printerRect);
  1010.     if (Return <= 0 || pr->b_print_abort) goto oops;
  1011.     }
  1012.     more = 1;
  1013.     while (more) {
  1014.     if (printer_bandable)
  1015.         DPtoLP(pr->printerDC, (LPPOINT) &printerRect, 2);
  1016.     Return = StretchDIBits(pr->printerDC,
  1017.         0, 0,
  1018.         printer_xacross, printer_yacross,
  1019.         0, 0,
  1020.         xdots, ydots,
  1021.         (LPSTR)&pixels[firstpixel], (LPBITMAPINFO)pDibInfo,
  1022.         DIB_RGB_COLORS, SRCCOPY);
  1023.     if (Return <= 0 || pr->b_print_abort) goto oops;
  1024.     more = 0;
  1025.     if (printer_bandable) {
  1026.         Return = Escape(pr->printerDC, NEXTBAND, 0, (LPSTR) NULL, (LPSTR) &printerRect);
  1027.         if (Return <= 0 || pr->b_print_abort) goto oops;
  1028.         more = ! (IsRectEmpty(&printerRect));
  1029.         }
  1030.     }
  1031.     Return = Escape(pr->printerDC, NEWFRAME, 0, NULL, NULL);
  1032.     if (Return <= 0 || pr->b_print_abort) goto oops;
  1033.     Return = Escape(pr->printerDC, ENDDOC, 0, NULL, NULL);
  1034.  
  1035. oops:
  1036.     EnableWindow(hwnd, TRUE);
  1037.     DestroyWindow(pr->h_pabort_dialog);
  1038.     FreeProcInstance(p_print_abort);
  1039.     FreeProcInstance(p_pabort_dialog);
  1040.     default_dib_palette();   /* replace the palette */
  1041.     end_wait();
  1042.     if (!pr->b_print_abort && Return <= 0) {
  1043.         char reason[80];
  1044.         strcpy(reason,"Print failed - General error or unspecified reason");
  1045.     if (Return == SP_OUTOFDISK)
  1046.         strcpy(reason,"Print failed - out of disk space");
  1047.     if (Return == SP_OUTOFMEMORY)
  1048.         strcpy(reason,"Print failed - out of memory");
  1049.     if (Return == 0)
  1050.         strcpy(reason,"Print failed -  driver doesn't have a function we need");
  1051.         stopmsg(0,reason);
  1052.     }
  1053.  
  1054. win_print_exit: /* cleanup */
  1055.     if (pr->printerDC)
  1056.     DeleteDC(pr->printerDC);
  1057.     if (pr->hdm) {
  1058.     GlobalUnlock(pr->hdm); /* DEVMODE */
  1059.     GlobalFree(pr->hdm);
  1060.     }
  1061.     GlobalUnlock(hpr); /* general vars */
  1062.     GlobalFree(hpr);
  1063.  
  1064. }
  1065.  
  1066. /*
  1067.     Delay code - still not so good for a multi-tasking environment, 
  1068.     but what the hell...
  1069. */
  1070.  
  1071. DWORD DelayCount;
  1072.  
  1073. DWORD DelayMillisecond(void)
  1074. {
  1075.    DWORD i;
  1076.  
  1077.    i = 0;
  1078.    while(i != DelayCount)
  1079.       i++;
  1080.    return(i);
  1081. }
  1082.  
  1083. void delay(DWORD milliseconds)
  1084. {
  1085.    DWORD n, i, j;
  1086.  
  1087. if (DelayCount == 0) {      /* use version 3.1's 1ms timer */
  1088.  
  1089.     TIMERINFO timerinfo;
  1090.  
  1091.     timerinfo.dwSize = sizeof(timerinfo);
  1092.     TimerCount(&timerinfo);
  1093.     n = timerinfo.dwmsSinceStart;
  1094.     i = n + milliseconds;
  1095.     for (;;) {
  1096.         keypressed();        /* let the other folks in */
  1097.         TimerCount(&timerinfo);
  1098.         j = timerinfo.dwmsSinceStart;
  1099.         if (j < n || j >= i)
  1100.             break;
  1101.         }   
  1102.  
  1103.    }
  1104. else {
  1105.    for(n = 0; n < milliseconds; n++)
  1106.       DelayMillisecond();
  1107.    }
  1108.  
  1109. }
  1110.  
  1111. void CalibrateDelay(void)
  1112. {
  1113.     DWORD Now, Time, Delta, TimeAdj;
  1114.     
  1115.     /* this logic switches tothe fast timer logic supplied by TimerCount */
  1116.     DelayCount = 0;
  1117.     return;
  1118.  
  1119.    DelayCount = 128;
  1120.  
  1121.    /* Determine the Windows timer resolution.  It's usually 38ms in
  1122.       version 3.0, but that may change latter. */
  1123.    Now = Time = GetCurrentTime();
  1124.    while(Time == Now)
  1125.       Now = GetCurrentTime();
  1126.  
  1127.    /* Logrithmic Adjust */
  1128.    Delta = Now - Time;
  1129.    Time = Now;
  1130.    while(Time == Now)
  1131.    {
  1132.       delay(Delta);
  1133.       Now = GetCurrentTime();
  1134.       if(Time == Now)
  1135.       {
  1136.          /* Resynch */
  1137.          Time = Now = GetCurrentTime();
  1138.          while(Time == Now)
  1139.             Now = GetCurrentTime();
  1140.          Time = Now;
  1141.          DelayCount <<= 1;
  1142.       }
  1143.    }
  1144.  
  1145.    /* Linear Adjust */
  1146.    Time = Now;
  1147.    TimeAdj = (DelayCount - (DelayCount >> 1)) >> 1;
  1148.    DelayCount -= TimeAdj;
  1149.    while(TimeAdj > 16)
  1150.    {
  1151.       delay(Delta);
  1152.       TimeAdj >>= 1;
  1153.       if(GetCurrentTime() == Now)
  1154.          DelayCount += TimeAdj;
  1155.       else
  1156.          DelayCount -= TimeAdj;
  1157.  
  1158.       /* Resynch */
  1159.       Time = Now = GetCurrentTime();
  1160.       while(Time == Now)
  1161.          Now = GetCurrentTime();
  1162.       Time = Now;
  1163.    }
  1164. }
  1165.  
  1166. /*
  1167.     Color-cycling logic
  1168.     includes variable-delay capabilities
  1169. */
  1170.  
  1171. extern int win_cycledir, win_cyclerand, win_cyclefreq, win_cycledelay;
  1172.  
  1173. extern HANDLE  hPal;       /* Palette Handle */
  1174. extern LPLOGPALETTE pLogPal;  /* pointer to the application's logical palette */
  1175. extern unsigned char far win_dacbox[256][3];
  1176. #define PALETTESIZE 256           /* dull-normal VGA            */
  1177.  
  1178. static int win_fsteps[] = {54, 24, 8};
  1179.  
  1180. int win_animate_flag = 0;
  1181. int win_syscolorindex[21];
  1182. DWORD win_syscolorold[21];
  1183. DWORD win_syscolornew[21];
  1184.  
  1185. extern int debugflag;
  1186.  
  1187. win_cycle()
  1188. {
  1189. int istep, jstep, fstep, step, oldstep, last, next, maxreg;
  1190. int incr, fromred, fromblue, fromgreen, tored, toblue, togreen;
  1191. HDC hDC;              /* handle to device context        */
  1192.  
  1193. fstep = 1;                /* randomization frequency    */
  1194. oldstep = 1;                /* single-step            */
  1195. step = 256;                /* single-step            */
  1196. incr = 999;                /* ready to randomize        */
  1197. maxreg = 256;                /* maximum register to rotate    */
  1198. last = maxreg-1;            /* last box that was filled    */
  1199. next = 1;                /* next box to be filled    */
  1200. if (win_cycledir < 0) {
  1201.     last = 1;
  1202.     next = maxreg;
  1203.     }
  1204.  
  1205. win_title_text(2);
  1206.  
  1207. srand((unsigned)time(NULL));        /* randomize things        */
  1208.  
  1209. hDC = GetDC(GetFocus());
  1210.  
  1211. win_animate_flag = 1;
  1212. SetPaletteEntries(hPal, 0, pLogPal->palNumEntries, pLogPal->palPalEntry);
  1213. SelectPalette (hDC, hPal, 1);
  1214.  
  1215. if ((iNumColors == 16 || debugflag == 1000) && !win_systempaletteused) {
  1216.     int i;
  1217.     DWORD white, black;
  1218.     win_systempaletteused = TRUE;
  1219.     white = 0xffffff00;
  1220.     black = 0;
  1221.     for (i = 0; i <= COLOR_ENDCOLORS; i++) {
  1222.     win_syscolorindex[i] = i;
  1223.     win_syscolorold[i] = GetSysColor(i);
  1224.     win_syscolornew[i] = black;
  1225.     }
  1226.     win_syscolornew[COLOR_BTNTEXT] = white;
  1227.     win_syscolornew[COLOR_CAPTIONTEXT] = white;
  1228.     win_syscolornew[COLOR_GRAYTEXT] = white;
  1229.     win_syscolornew[COLOR_HIGHLIGHTTEXT] = white;
  1230.     win_syscolornew[COLOR_MENUTEXT] = white;
  1231.     win_syscolornew[COLOR_WINDOWTEXT] = white;
  1232.     win_syscolornew[COLOR_WINDOWFRAME] = white;
  1233.     win_syscolornew[COLOR_INACTIVECAPTION] = white;
  1234.     win_syscolornew[COLOR_INACTIVEBORDER] = white;
  1235.     SetSysColors(COLOR_ENDCOLORS,(LPINT)win_syscolorindex,(LONG FAR *)win_syscolornew);
  1236.     SetSystemPaletteUse(hDC,SYSPAL_NOSTATIC);
  1237.     UnrealizeObject(hPal);
  1238.     }
  1239.  
  1240. while (time_to_cycle) {
  1241.     if (win_cyclerand) {
  1242.     for (istep = 0; istep < step; istep++) {
  1243.         jstep = next + (istep * win_cycledir);
  1244.         if (jstep <=      0) jstep += maxreg-1;
  1245.         if (jstep >= maxreg) jstep -= maxreg-1;
  1246.         if (++incr > fstep) {    /* time to randomize    */
  1247.         incr = 1;
  1248.         fstep = ((win_fsteps[win_cyclefreq]*
  1249.             (rand() >> 8)) >> 6) + 1;
  1250.         fromred   = dacbox[last][0];
  1251.         fromgreen = dacbox[last][1];
  1252.         fromblue  = dacbox[last][2];
  1253.         tored      = rand() >> 9;
  1254.         togreen   = rand() >> 9;
  1255.         toblue      = rand() >> 9;
  1256.         }
  1257.         dacbox[jstep][0] = fromred     + (((tored   - fromred  )*incr)/fstep);
  1258.         dacbox[jstep][1] = fromgreen + (((togreen - fromgreen)*incr)/fstep);
  1259.         dacbox[jstep][2] = fromblue  + (((toblue  - fromblue )*incr)/fstep);
  1260.         }
  1261.     }
  1262.     if (step >= 256) step = oldstep;
  1263.  
  1264.     spindac(win_cycledir,step);
  1265.     delay(win_cycledelay);
  1266.     AnimatePalette(hPal, 0, pLogPal->palNumEntries, pLogPal->palPalEntry);
  1267.     RealizePalette(hDC);
  1268.     keypressed();
  1269.     if (win_cyclerand == 2) {
  1270.     win_cyclerand = 1;
  1271.     step = 256;
  1272.     }
  1273.     }
  1274.  
  1275. win_animate_flag = 0;
  1276. ReleaseDC(GetFocus(),hDC);
  1277.  
  1278. win_title_text(0);
  1279.  
  1280. }
  1281.  
  1282. /* cursor routines */
  1283.  
  1284. extern HANDLE hSaveCursor;           /* the original cursor value */
  1285. extern HANDLE hHourGlass;           /* the hourglass cursor value */
  1286.  
  1287. start_wait()
  1288. {
  1289.    hSaveCursor = SetClassWord(hwnd, GCW_HCURSOR, hHourGlass);
  1290. }
  1291.  
  1292. end_wait()
  1293. {
  1294.    SetClassWord(hwnd, GCW_HCURSOR, hSaveCursor);
  1295. }
  1296.  
  1297. /* video-mode routines */
  1298.  
  1299. extern int    viewwindow;        /* 0 for full screen, 1 for window */
  1300. extern float  viewreduction;        /* window auto-sizing */
  1301. extern float  finalaspectratio;     /* for view shape and rotation */
  1302. extern int    viewxdots,viewydots;    /* explicit view sizing */
  1303. extern int    fileydots, filexdots, filecolors;
  1304. extern float  fileaspectratio;
  1305. extern int    skipxdots,skipydots;    /* for decoder, when reducing image */
  1306.  
  1307. int get_video_mode(struct fractal_info *info)
  1308. {
  1309.    viewwindow = viewxdots = viewydots = 0;
  1310.    fileaspectratio = .75;
  1311.    skipxdots = skipydots = 0;
  1312.    return(0);
  1313. }
  1314.  
  1315.  
  1316. void spindac(int direction, int step)
  1317. {
  1318. int i, j, k;
  1319. int cycle_start, cycle_fin;
  1320. extern int rotate_lo,rotate_hi;
  1321. char tempdacbox;
  1322.  
  1323. cycle_start = 0;
  1324. cycle_fin = 255;
  1325. if (time_to_cycle) {
  1326.    cycle_start = rotate_lo;
  1327.    cycle_fin = rotate_hi;
  1328.    }
  1329.  
  1330. for (k = 0; k < step; k++) {
  1331.     if (direction > 0) {
  1332.     for (j = 0; j < 3; j++) {
  1333.         tempdacbox = dacbox[cycle_fin][j];
  1334.         for (i = cycle_fin; i > cycle_start; i--)
  1335.         dacbox[i][j] = dacbox[i-1][j];
  1336.         dacbox[cycle_start][j] = tempdacbox;
  1337.         }
  1338.     }
  1339.     if (direction < 0) {
  1340.     for (j = 0; j < 3; j++) {
  1341.         tempdacbox = dacbox[cycle_start][j];
  1342.         for (i = cycle_start; i < cycle_fin; i++)
  1343.         dacbox[i][j] = dacbox[i+1][j];
  1344.         dacbox[cycle_fin][j] = tempdacbox;
  1345.         }
  1346.     }
  1347.     }
  1348.  
  1349.     /* fill in intensities for all palette entry colors */
  1350.     for (i = 0; i < 256; i++) {
  1351.     pLogPal->palPalEntry[i].peRed    = ((BYTE)dacbox[i][0]) << 2;
  1352.     pLogPal->palPalEntry[i].peGreen = ((BYTE)dacbox[i][1]) << 2;
  1353.     pLogPal->palPalEntry[i].peBlue    = ((BYTE)dacbox[i][2]) << 2;
  1354.     pLogPal->palPalEntry[i].peFlags = PC_RESERVED;
  1355.     }
  1356.  
  1357.     if (!win_animate_flag) {
  1358.     HDC hDC;
  1359.     hDC = GetDC(GetFocus());
  1360.     SetPaletteEntries(hPal, 0, pLogPal->palNumEntries, pLogPal->palPalEntry);
  1361.     SelectPalette (hDC, hPal, 1);
  1362.     RealizePalette(hDC);
  1363.     ReleaseDC(GetFocus(),hDC);
  1364.         /* for non-palette-based adapters, redraw the image */
  1365.     if (!iRasterCaps) {
  1366.             InvalidateRect(hwnd, NULL, FALSE);
  1367.             }
  1368.     }
  1369. }
  1370.  
  1371. restoredac()
  1372. {
  1373. int iLoop;
  1374. int j;
  1375.  
  1376.     /* fill in intensities for all palette entry colors */
  1377.     for (iLoop = 0; iLoop < PALETTESIZE; iLoop++)
  1378.     for (j = 0; j < 3; j++)
  1379.         dacbox[iLoop][j] = win_dacbox[iLoop][j];
  1380.     spindac(0,1);
  1381. }
  1382.  
  1383. extern int colorstate;
  1384. extern char    colorfile[];
  1385.  
  1386. int ValidateLuts( char * fn )
  1387. {
  1388. FILE * f;
  1389. unsigned    r, g, b, index;
  1390. unsigned char    line[101];
  1391. unsigned char    temp[81];
  1392.     strcpy (temp,fn);
  1393.     if (strchr(temp,'.') == NULL) /* Did name have an extension? */
  1394.         strcat(temp,".map");  /* No? Then add .map */
  1395.     findpath( temp, line);          /* search the dos path */
  1396.     f = fopen( line, "r" );
  1397.     if (f == NULL)
  1398.         return 1;
  1399.     for( index = 0; index < 256; index++ ) {
  1400.         if (fgets(line,100,f) == NULL)
  1401.             break;
  1402.         sscanf( line, "%d %d %d", &r, &g, &b );
  1403.         /** load global dac values **/
  1404.         dacbox[index][0] = r >> 2;    /* maps default to 8 bits */
  1405.         dacbox[index][1] = g >> 2;    /* DAC wants 6 bits */
  1406.         dacbox[index][2] = b >> 2;
  1407.     }
  1408.     fclose( f );
  1409.     colorstate = 2;
  1410.     strcpy(colorfile,temp);
  1411.     return 0;
  1412. }
  1413.  
  1414. int win_thinking = 0;
  1415.  
  1416. int thinking(int waiting, char *dummy)
  1417. {
  1418. if (waiting && ! win_thinking) {
  1419.     win_thinking = 1;
  1420.     start_wait();
  1421.     }
  1422. if (!waiting)
  1423.     end_wait();
  1424. return(keypressed());
  1425. }
  1426.  
  1427. extern HWND far wintext_hWndCopy;                /* a Global copy of hWnd */
  1428.  
  1429. /* Call for help caused by pressing F1 inside the "fractint-style"
  1430.    prompting routines */
  1431. int winfract_help()
  1432. {
  1433.         WinHelp(wintext_hWndCopy,szHelpFileName,HELP_INDEX,0L);
  1434. }
  1435.  
  1436. int far_strlen(char far *string) {
  1437. int i;
  1438. for (i = 0; ; i++)
  1439.     if (string[i] == 0)
  1440.     return(i);
  1441. }
  1442.  
  1443. int far_strnicmp(char far *string1, char far *string2, int maxlen) {
  1444. int i;
  1445. unsigned char j, k;
  1446. for (i = 0;i < maxlen ; i++) {
  1447.     j = string1[i];
  1448.     k = string2[i];
  1449.     if (j >= 'a' && j <= 'z') j -= ('a' - 'A');
  1450.     if (k >= 'a' && k <= 'z') k -= ('a' - 'A');
  1451.     if (j-k != 0)
  1452.     return(j-k);
  1453.     }
  1454. return(0);
  1455. }
  1456.  
  1457. int far_memcpy(void far *string1, void far *string2, int maxlen) {
  1458. int i;
  1459. for (i = 0;i < maxlen ; i++)
  1460.     ((char far *)string1)[i] = ((char far *)string2)[i];
  1461. }
  1462.  
  1463. int far_memcmp(void far *string1, void far *string2, int maxlen) {
  1464. int i;
  1465. unsigned char j, k;
  1466. for (i = 0;i < maxlen ; i++) {
  1467.     j = ((char far *)string1)[i];
  1468.     k = ((char far *)string2)[i];
  1469.     if (j-k != 0)
  1470.     return(j-k);
  1471.     }
  1472. return(0);
  1473. }
  1474.  
  1475. int far_memset(void far *string1, char char2, int maxlen) {
  1476. int i;
  1477. for (i = 0;i < maxlen ; i++)
  1478.     ((char far *)string1)[i] = char2;
  1479. }
  1480.  
  1481. /* dummy out the environment entries, as we never use them */
  1482. int _setenvp(){return(0);}
  1483.  
  1484. /* fake/not-yet-implemented subroutines */
  1485.  
  1486. void farmessage(unsigned char far *foo) {}
  1487. void setvideomode(int foo1, int foo2, int foo3, int foo4) {}
  1488. int fromvideotable() {}
  1489. int home() {}
  1490.  
  1491. int intro_overlay() {}
  1492. int rotate_overlay() {}
  1493. int printer_overlay() {}
  1494. int pot_startdisk() {}
  1495. int SetTgaColors() {}
  1496. int startdisk() {}
  1497. int enddisk() {}
  1498. int readdisk() {}
  1499. int writedisk() {}
  1500. int nosnd(){}
  1501. int snd(){}
  1502. int targa_startdisk(){}
  1503. int targa_writedisk(){}
  1504. int targa_readdisk(){}
  1505. int SetColorPaletteName() {}
  1506. int findfont() {return(0);}
  1507. int readticker(){return(0);}
  1508. int EndTGA(){}
  1509.  
  1510. int dvid_status(){}
  1511. int tovideotable(){}
  1512.  
  1513. void load_mat(){}
  1514. void mult_vec_iit(){}
  1515. int check_vidmode_keyname(){return(0);}
  1516.  
  1517. void TranspPerPixel(){}
  1518.